package structure;

import utilities.rle2dUtilities;

public class Square extends Area implements AreaInf {
	private int a;

	public Square (int a, int x, int y, int color, int byteSize) {
		this.a = a;
		super.setX(x);
		super.setY(y);
		super.setColor(color);
		super.setByteSize(byteSize);
		this.evalPriority();
		this.setKind(rle2dUtilities.SQUARE);
	}
	
	public Square (int a, int x, int y, int color,int priority,int byteSize) {
		this.a = a;
		super.setX(x);
		super.setY(y);
		super.setColor(color);
		super.setByteSize(byteSize);
		this.setPriority(priority);
		this.setKind(rle2dUtilities.SQUARE);
	}
	
	public int getA() {
		return a;
	}

	public void setA(int a) {
		this.a = a;
	}

	@Override
	public void evalPriority() {
		// TODO Auto-generated method stub
		super.setPriority(a*a);
		
	}

	@Override
	public byte[] getBinary() {
		int size = 2*super.getByteSize()+2;
		byte[] binary = new byte[size];
		
		if (super.getByteSize()>1) {
			// X
			binary[0] = (byte)(super.getX());
			binary[1] = (byte)(super.getX() >> 8);
			// Y
			binary[2] = (byte)(super.getY());
			binary[3] = (byte)(super.getY() >> 8);
			// A
			binary[4] = (byte)(getA());
			//COLOR
			binary[5] = (byte)(super.getColor());
		}
		else {
			// X
			binary[0] = (byte)(super.getX());
			// Y
			binary[1] = (byte)(super.getY());
			// A
			binary[2] = (byte)(getA());
			//COLOR
			binary[3] = (byte)(super.getColor());
		}
		return binary;
	}
}
